//授權碼： jyfxzefmrdmcdiec
//不做封裝，只發一個郵件
import { SendEmail } from "../type";
const nodemailer = require("nodemailer");

//暫不使用qq郵箱發送，會有代理設置出錯

async function CodeEmail(options: SendEmail): Promise<boolean> {
  //連接郵箱
  const transporter = nodemailer.createTransport({
    service: "qq",
    host: "smtp.qq.com",
    port: 456,
    secure: false,
    auth: {
      pass: "jyfxzefmrdmcdiec",
      user: "2472904756@qq.com",
    },
  });
  return new Promise((resolve, reject) => {
    transporter.sendMail(options, (err: any, result: any) => {
      if (err) {
        transporter.close();
        reject(err);
      } else {
        transporter.close();
        resolve(result);
      }
    });
  });
}

export { CodeEmail };
